package org.example;

public class Test3 {
    //leetcode 283 移动零 https://leetcode.cn/problems/move-zeroes/
    public void moveZeroes(int[] nums) {
        //双指针问题，0-slow之间的元素是不含0的元素，slow-fast之间的元素是0元素，fast-(n-1)之间的元素是待扫描的元素
        int n = nums.length;
        int slow = -1, fast = 0;
        while (fast < n) {
            if (nums[fast] != 0) {
                int tmp = nums[++slow];
                nums[slow] = nums[fast];
                nums[fast] = tmp;
            }
            fast++;
        }
    }
}
